<template>
	<view>
		这是test页面
		<button @click="uploadImage">上传图片</button>
		<button @click="fetchData">获取测试数据</button>
		<image v-if="imageUrl" :src="imageUrl" mode="aspectFit"></image>
		<view v-if="weatherData" class="weather-info">
			<text>当前气温: {{weatherData.temperature}}℃</text>
			<text>当前风向: {{weatherData.windDirection}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imageUrl: '',
				weatherData: null // 用于存储天气数据
			}
		},
		methods: {
			uploadImage() {
				uni.chooseImage({
					count: 1,
					sourceType: ['album', 'camera'], 
					success: (res) => {
						const tempFilePaths = res.tempFilePaths;
						this.imageUrl = tempFilePaths[0];
					}
				});
			},
			fetchData() {
				uni.request({
					url: 'http://127.0.0.1:9999/test',
					// function (can1,caN2)
					success: (ookk) => {
						console.log('--ookk---')
						console.log(ookk)
						
						console.log('接口返回数据:', ookk.data['气温']);
						this.weatherData = {
							temperature: ookk.data['气温'],
							windDirection: ookk.data['风向']
						};
						uni.showToast({
							title: '数据获取成功',
							icon: 'none'
						});
					},
					fail: (err) => {
						console.error('接口请求失败:', err);
						uni.showToast({
							title: '数据获取失败',
							icon: 'none'
						});
					}
				});
			}
		}
	}
</script>

<style>
	image {
		width: 100%;
		height: 300rpx;
		margin-top: 20rpx;
	}
	.weather-info {
		margin-top: 20rpx;
		display: flex;
		flex-direction: column;
		gap: 10rpx;
	}
	.weather-info text {
		font-size: 28rpx;
		color: #333;
	}
</style>
